package com.ihighest.app.infox.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ihighest.app.infox.R;
import com.ihighest.app.infox.bean.AddressListItem;
public class AddressAdapter extends BaseAdapter {


	private LayoutInflater mInflater = null;
	private Context context;
	private List<AddressListItem> myList;
	private int mSelect;

	public AddressAdapter(Context context, List<AddressListItem> myList) { 
		this.context = context; 
		mInflater = LayoutInflater.from(this.context);
		this.myList = myList;
	}

	public int getCount() {
		return myList.size(); 
	} 
	public Object getItem(int position) {
		return myList.get(position);
	} 
	public long getItemId(int position) {
		return position;
	} 
	@Override
	public View getView(final int index, View view, ViewGroup arg2) {
		ViewHolder holder = null;
		if(view==null){
			holder = new ViewHolder();
			view = mInflater.inflate(R.layout.infox_items_address_listview, null);
			holder.address_tv = (TextView)view.findViewById(R.id.address_tv);
			view.setTag(holder);
		}else{
			holder = (ViewHolder) view.getTag();
		}
		holder.address_tv.setText(myList.get(index).getName());
		if(mSelect == index)
		{
			holder.address_tv.setTextColor(Color.RED);
		}
		else
		{
			holder.address_tv.setTextColor(Color.BLACK);
		}
		return view;
	}
	private class ViewHolder {
		public TextView address_tv;
	}
	public void changeSelected(int positon){ //刷新方法
		if(positon != mSelect){
			mSelect = positon;
			notifyDataSetChanged();
		}
	}
}